package xml;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.Iterator;

/**
 * @Author wangzhipeng
 * @Date 2020-08-25 7:14 下午
 * @Description
 */
public class Demo4jTest {
    public static void main(String[] args) {

        try {
            //创建解析器
            SAXReader reader = new SAXReader();
            //通过解析器的read方法将配置文件读取到内存中，生成一个document[org.demo4j]对象树
            Document document = reader.read("src/main/java/xml/student.xml");
            //获取根节点
            Element root = document.getRootElement();
            //开始遍历根节点
            for(Iterator<Element> rootIter = root.elementIterator();rootIter.hasNext();){
                Element studentElt = rootIter.next();
                for(Iterator<Element> innerIter = studentElt.elementIterator();innerIter.hasNext();){
                    Element innerElt = innerIter.next();
                    String innerValue = innerElt.getStringValue();
                    System.out.println(innerValue);
                }
                System.out.println("__________________");
            }

        } catch (DocumentException e) {
            e.printStackTrace();
        }

    }
}
